package com.zhongketech.sunflower;

import com.zhongketech.sunflower.transport.LogUtil;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MyToast {

	private static String TAG = "MyToast";
	private static MyToast instance = new MyToast();
	private Handler toaster;
	Context context  = null;

	private static final int SHOW_KILLAPP_TIPS = 0;

	private MyToast(){

		context = MyApplication.getInstance().getApplicationContext();

		toaster = new Handler() {
			public void handleMessage(Message msg) {
				switch (msg.arg1) {
				case SHOW_KILLAPP_TIPS:

					break;

				default:
					break;
				}
			}
		};
	};

	public static MyToast getInstance() 
	{
		return instance;
	}

	private String showId = null;
	public void showBox(final String id)
	{

		toaster.post(new Runnable() {
			@Override
			public void run() {
				AlertDialog.Builder dialog=new AlertDialog.Builder(context);
				//				LinearLayout linearLayout = (LinearLayout) findViewById(R.id.app_kill_dialog);
				dialog.setTitle("提示");
				dialog.setIcon(R.drawable.kill_app_bg);  
				//				dialog.setView(view)
				//				dialog.setMessage("应用已被家长禁止启动");
				//				dialog.setPositiveButton("停止测试",new DialogInterface.OnClickListener() {
				//					@Override
				//					public void onClick(DialogInterface dialog, int which) {
				//						// TODO Auto-generated method stub
				//						//点击后跳转到某个Activity
				//						Intent result = new Intent(context,xxx.class);
				//						result.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				//						context.startActivity(result);
				//					}
				//				});
				AlertDialog mDialog=dialog.create();
				mDialog.setOnCancelListener(new OnCancelListener() {

					@Override
					public void onCancel(DialogInterface dialog) {
						// TODO Auto-generated method stub
						showId = null;
					}
				});
				mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);//设定为系统级警告，关键
				if(null == showId)
				{
					mDialog.show();	
					showId = id;
				}

			}
		});

	}	

	public void showAppKill()
	{
		toaster.post(new Runnable() {
			@Override
			public void run() {
				Intent i = new Intent();
				i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				i.setClassName("com.zhongketech.sunflower", "com.zhongketech.sunflower.activity.AppKillActivity");
				context.startActivity(i);
			}
		});
	}

	public void lockPhone()
	{
		toaster.post(new Runnable() {
			@Override
			public void run() {
				Intent i = new Intent();
				i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				i.setClassName("com.zhongketech.sunflower", "com.zhongketech.sunflower.activity.LockPhoneActivity");
				context.startActivity(i);
			}
		});
	}

	public void EyesLockPhone()
	{
		toaster.post(new Runnable() {
			@Override
			public void run() {
				Intent i = new Intent();
				i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				i.setClassName("com.zhongketech.sunflower", "com.zhongketech.sunflower.activity.EyesLockPhoneActivity");
				context.startActivity(i);
			}
		});
	}

	public void show(final String info)
	{
		LogUtil.i("ZK", info);
		if(null == info)
		{
			return;
		}

		toaster.post(new Runnable() {
			@Override
			public void run() {
				Toast.makeText(context, info,
						Toast.LENGTH_SHORT).show();

			}
		});
	}

}
